package com.llk.pool.mapper;

import com.llk.pool.domain.User;
import com.llk.pool.enums.UserSexEnum;
import com.llk.pool.mapper.sql.UserMapperProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * mybatis的mapper文件，由于在Application中添加了MapperScan所以不需要在这里添加注解了
 * Created by zhou on 17-4-28.
 */
@Mapper
public interface UserMapper{

    /*
     * 获取所有的User
     *
     * @return
     */
    @Select("select * from users")
    @Results(
            {@Result(property = "userSex", column = "user_sex", javaType = UserSexEnum.class),
                    @Result(property = "nickName", column = "nick_name")
            }
    )
    List<User> getAll();


    @Select("select * from users where id = #{id}")
    @Results(
            {@Result(property = "userSex", column = "user_sex", javaType = UserSexEnum.class),
                    @Result(property = "nickName", column = "nick_name")
            }
    )
    User getOne(Long id);

    @Insert("insert into users(userName, passWord, user_sex, nick_name) " +
            "values( #{userName}, #{passWord}, #{userSex}, #{nickName})")
    void insert(User user);


    //@Update("update users set userName=#{userName}, passWord=#{passWord}, user_sex=#{userSex},nick_name=#{nickName} where id=#{id}")
    @UpdateProvider(type = UserMapperProvider.class, method = "update")
    void update(User user);

    @Delete("delete from users where id = #{id}")
    void delete(Long id);

    //执行sql,设置当前的auto_increment
    @UpdateProvider(type = UserMapperProvider.class, method = "setAutoIncrement")
    void setAutoIncrement(Long id);

    //执行sql，获取当前的auto_increment
    @SelectProvider(type = UserMapperProvider.class, method = "getAutoIncrement")
    Long getAutoIncrement();


    //执行sql，获取当前的auto_increment
    @SelectProvider(type = UserMapperProvider.class, method = "getCount")
    int count ();

    @Results(
            {@Result(property = "userSex", column = "user_sex", javaType = UserSexEnum.class),
                    @Result(property = "nickName", column = "nick_name")
            }
    )
    @SelectProvider(type = UserMapperProvider.class, method = "loadUserList")
    List<User> loadUserList(int pageSize, int startRecord, String sortColumn, String sortDir, String searchValue);



}
